package cn.itsource.zcn.org.mapper;

import cn.itsource.zcn.org.domain.Department;
import cn.itsource.zcn.org.query.DepartmentQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * (Department)表数据库访问层
 *
 * @author makejava
 * @since 2021-08-06 17:44:16
 */
public interface DepartmentMapper {

    /**
     * 新增数据
     *
     * @param Department 实例对象
     */
    @Insert("insert into t_department" +
            "(sn,name,state,manager_id,parent_id)" +
            "values (#{sn},#{name},#{state},#{manager.id},#{parent.id})")
    void save(Department Department);

    /**
     * 修改数据
     *
     * @param Department 实例对象
     */
    @Update("update t_department set " +
            "sn=#{sn},name=#{name},state=#{state},manager_id=#{manager.id},parent_id=#{parent.id}" +
            " where id=#{id}")
    void update(Department Department);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     */
    @Delete("delete from t_department where id = #{id} ")
    void delete(Long id);


    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Select("select * from t_department where id = #{id}")
    Department queryById(Long id);

    /**
     * 查询全部
     *
     * @return 对象列表
     */
    @Select("select * from t_department")
    List<Department> queryAll();

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Department> 实例对象列表
     */
    void insertBatch(@Param("Departments") List<Department> entities);

    /*
     * 查询总条数
     */
    Integer count(DepartmentQuery departmentQuery);

    /*
     * 根据条件查询数据集合
     */
    List<Department> query(DepartmentQuery departmentQuery);
    /**
     * 批量删除
     * @return AjaxResult
     */
    void patchDelete(Long[] ids);
}

